/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-09-09
 * Time: 20:56
 */
class Solution7 {
    public int firstMissingPositive(int[] nums) {
        int n = nums.length;
        int[] hash = new int[n+1];
        for (int i = 0; i < n; i++) {
            //只统计大小在1到n+1区间的数字
            if (nums[i] >= 1 && nums[i] <= n+1) {
                hash[nums[i]-1]++;
            }
        }
        for (int i = 0; i < hash.length; i++) {
            if (hash[i] == 0) {
                return i+1;
            }
        }
        return -1;
    }
}

